package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/FeedBack")
@CrossOrigin(origins="*")
public class FeedBackController {
    @Autowired
    private FeedBackService feedBackService;
//    @RequestMapping("/feekbacek")
    //学生反馈模块
//    public ResultBody feekbacek(@RequestBody Map<String,Object> map) {
//        //判断参数是否完整
//        if(map.get("courseid") == null||map.get("usernumber") == null||map.get("coursepoint")==null||map.get("question")==null) {
//            return new ResultBody(404,"参数错误",false);
//        }
//        String question = map.get("question").toString();
//        String usernumber = map.get("usernumber").toString();
//        Object object1=map.get("courseid");
//        Object object2=map.get("coursepoint");
//        Integer courseid;
//        Double coursepoint;
//        if(object1 instanceof String ) {
//            courseid = Integer.parseInt((String)object1);
//        }
//        else if (object1 instanceof Integer) {
//            courseid=(Integer) object1;
//        }
//        else
//            return new ResultBody(400, "性别格式错误", false);
//
//        if(object2 instanceof String) {
//            coursepoint = Double.parseDouble((String)object2);
//        }
//        else if (object2 instanceof Double) {
//            coursepoint =(Double) object2;
//        }
//        else
//            return new ResultBody(400, "性别格式错误", false);
//        return feedBackService.feedback(courseid,usernumber,coursepoint,question);
//    }
    //查看学生反馈模块
    @RequestMapping("/lookfeekbacek")
    public ResultBody lookfeekbacek(@RequestBody Map<String,Object> map) {
        if(map.get("courseid")==null)
        {
            return new ResultBody(404,"缺少参数",false);
        }
        Object object1=map.get("courseid");
            Integer courseid;
        if(object1 instanceof String ) {
            courseid=Integer.parseInt((String)object1);
        }
        else if(object1 instanceof Integer) {
            courseid=(Integer) object1;
        }
        else
            return new ResultBody(400,"格式错误",false);
        return feedBackService.lookfeedback(courseid);
    }
    @RequestMapping("/lookfeedbackpoint")
    public ResultBody lookfeedbackpoint(@RequestBody Map<String,Object> map) {
        if(map.get("courseid")==null) {
        return new ResultBody(404,"参数错误",false);
        }
        return feedBackService.lookfeedbackpoint(map);
    }
    //查看所有反馈（管理员端）
    @RequestMapping("/lookallfeekbacek")
    public ResultBody lookallfeekbacekpoint() {
        return feedBackService.getFeedbackData();
    }
    @RequestMapping("/lookaallfeedbackpoint")
    public ResultBody lookaallfeedbackpoint() {
        return feedBackService.lookallfeedbackpoint();
    }
//    @RequestMapping("/displayfeedback")
//    public ResultBody displayfeedback() {
//        return feedBackService.displayfeedback();
//    }
//    @RequestMapping("/lookfeedbackname")
//    public  ResultBody lookfeedbackname() {
//        return feedBackService.lookfeedbackname();
//    }
}
